﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region Version Info
/* ========================================================================
* 【本页面功能概述】
*
* 作者：wangjianfeng 创建时间：2012/9/15 14:33:00
* 文件名：PowerGroup.cs
*
* 修改者： 时间：
* 修改说明：
* ========================================================================
*/
#endregion
namespace ChinaLeg.Cache
{
    /// <summary>
    /// 管理员权限组
    /// </summary>
    public class PowerGroup
    {

        #region 类实例化单件模式
        static PowerGroup instance = null;
        static readonly object padlock = new object();

        public static PowerGroup Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (padlock)
                    {
                        if (instance == null)
                        {
                            instance = new PowerGroup();
                        }
                    }
                }
                return instance;
            }
        }
        #endregion

        /// <summary>
        /// 获取权限管理员列表
        /// </summary>
        /// <returns></returns>
        public List<ChinaLeg.Model.PowerGroup> GetList()
        {
            string key = CacheKeys.Keys["PowerGroup"];
            if (System.Web.HttpContext.Current.Cache[key] == null)
            {
                List<ChinaLeg.Model.PowerGroup> list = ChinaLeg.BLL.PowerGroup.Instance.GetList();
                System.Web.HttpContext.Current.Cache.Insert(key, list, null, DateTime.Now.AddDays(1), TimeSpan.Zero);
                return list;
            }
            else
            {
                return System.Web.HttpContext.Current.Cache[key] as List<ChinaLeg.Model.PowerGroup>;
            }

        }

        /// <summary>
        /// 获取权限名称
        /// </summary>
        /// <param name="GroupId">权限ID</param>
        /// <returns></returns>
        public string GetPowerName(int GroupId)
        {
            List<ChinaLeg.Model.PowerGroup> list = GetList();

            var items = list.Where(p => p.Id == GroupId);
            foreach (var item in items)
            {
                return item.PowerName;
            }
            return "";
        }
    }
}
